package com.reflect.demo;

import java.lang.reflect.Modifier;

public class Dog extends Animal {
	Dog(){
		this("dog");
	}
	
	public String msg;
	
	public Dog(String name){
		super(name);
	}
	
	public Dog(String name, String address){
		super(name, address);
	}
	
	void display2(){
		System.out.println("?????............");
	}
	
	private void display1(){
		System.out.println("dog");
	}
	
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchFieldException{
//		Animal a = new Animal("a");
//		a.display();
//		
//		//((Dog)a).display();
//		
//		Animal a1 = new Dog();
//		a1.display();
//		((Dog)a1).display2();
		
		
//____________________________________________ start_____________________________________________________________________		
		
		String className = "com.reflect.demo.Dog";
		
		Class c1 = Class.forName(className);
		
		System.out.println("Class object name : " + c1.getName()+ "\n" );
		
		for(int j = 0; j<c1.getDeclaredFields().length; j++){
			System.out.println(c1.getDeclaredFields()[j].getName());
			System.out.println(c1.getDeclaredFields()[j].getType().getName() + "\n");
		
		}
		
		System.out.println("......................");
		
		for(int n = 0; n<c1.getDeclaredConstructors().length;n++){
			System.out.println(c1.getDeclaredConstructors()[n].getName());
			
			Class[] xt = c1.getDeclaredConstructors()[n].getParameterTypes();
			
			for(int m = 0; m<xt.length; ++m){
				System.out.print(xt[m].getName() + "  ");
			}
			
			System.out.println();
			
			System.out.println(Modifier.isPublic(c1.getDeclaredConstructors()[n].getModifiers()) + "  " + Modifier.toString(c1.getDeclaredConstructors()[n].getModifiers())  + "\n");
		}
		
		System.out.println("...........k............");
		
		for(int i = 0; i<c1.getMethods().length; i++){
			System.out.println(c1.getMethods()[i]);
			System.out.println(c1.getMethods()[i].getName() + " ...");
			System.out.println(c1.getMethods()[i].getReturnType().getName());
			System.out.println(c1.getMethods()[i].getTypeParameters() + "\n");
			
			System.out.println(c1.getMethods()[i].getDeclaringClass().getName());
			System.out.println("____________");
		}
		
		System.out.println("..........p.............");
		
		Animal a = (Animal) Class.forName(className).newInstance();
		
		System.out.println(System.getProperty("user.dir" + "ccc"));
//____________________________________________ end_____________________________________________________________________			
		
//____________________________________________ start Field get() _____________________________________________________________________			
//
//		Animal d = new Animal("dog1", "guangzhou");
//		
//		Class c2  = d.getClass();
//		
//		Field f = c2.getDeclaredField("name");
//		
//		f.setAccessible(true);
//		
//		f.set(d, "dog2");
//		
//		Object obj = f.get(d);
//		
//		String dogName = (String)obj;
//		
//		System.out.println(obj.getClass().getName());
//		
//		System.out.println(dogName);
		
		//System.out.println(obj1.toString());
		
		//String s = ((Animal)obj1).getName();
//____________________________________________ end _____________________________________________________________________			

	}

}
